#ifndef ELLOADING_H
#define ELLOADING_H

#include "../basic/elcomponent.h"
#include "../basic/elicon.h"

class ElLoading : public ElComponent
{
    Q_OBJECT
public:
    ElLoading(QWidget *target);
    ElLoading(QWidget *target, const QString &text);

    // target is equal to parent
    void setTarget(QWidget *target);
    QWidget *target() const;

    ElIcon *icon() const;
    void setIcon(ElIcon *icon);
    void setIcon(const QString &filename, int iconSize = 16);

    QString text() const;
    void setText(const QString &text);

    QColor background() const;
    void setBackground(const QColor &bgColor);

signals:
    void clicked();
    void appeared();
    void disappeared();

protected:
    void paintEvent(QPaintEvent *e) override;
    void showEvent(QShowEvent *e) override;
    void hideEvent(QHideEvent *e) override;
    void closeEvent(QCloseEvent *e) override;
    void mouseReleaseEvent(QMouseEvent *e) override;
    void initPalette() override;

private:
    Q_PROPERTY(QString text READ text WRITE setText)
    Q_PROPERTY(QColor background READ background WRITE setBackground)

    static const int Spacing;

    ElIcon *_icon = nullptr;
    QString _text;
    QColor _bg = Qt::black;
};

#endif // ELLOADING_H
